package dao.impl;

import java.util.List;

import libs.Global;
import models.Provider;
import dao.ProviderDao;

public class ProviderDaoImpl implements ProviderDao {

	@Override
	public List<Provider> selectAll() {
		return Global.entityManager.createQuery("SELECT prov FROM Provider AS prov", Provider.class).getResultList();
	}

	@Override
	public void insertOrUpdate(Provider provider) {
		Global.entityManager.getTransaction().begin();
		Global.entityManager.persist(provider);
		Global.entityManager.getTransaction().commit();
		
	}

	@Override
	public void delete(Provider provider) {
		Global.entityManager.getTransaction().begin();
		Global.entityManager.remove(provider);
		Global.entityManager.getTransaction().commit();
	}

}
